package com.ruoyi.asset.service.impl;

import java.util.List;

import com.ruoyi.common.core.redis.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.asset.mapper.AssetFlowTypeMapper;
import com.ruoyi.asset.domain.AssetFlowType;
import com.ruoyi.asset.service.IAssetFlowTypeService;

import javax.annotation.PostConstruct;

/**
 * 工单流程Service业务层处理
 * 
 * @author yepanpan
 * @date 2024-12-25
 */
@Service
public class AssetFlowTypeServiceImpl implements IAssetFlowTypeService 
{
    public static final String CACHE_MAP = "asset_flow_type";
    @Autowired
    private RedisCache redisCache;

    @Autowired
    private AssetFlowTypeMapper assetFlowTypeMapper;

    @PostConstruct
    public int reCache(){
        redisCache.deleteObject(CACHE_MAP);
        return 0;
    }

    /**
     * 查询工单流程
     * 
     * @param id 工单流程主键
     * @return 工单流程
     */
    @Override
    public AssetFlowType selectAssetFlowTypeById(Long id)
    {
        String key = "id_"+id;
        AssetFlowType assetFlowType = redisCache.getCacheMapValue(CACHE_MAP, key);
        if(assetFlowType != null){
            return assetFlowType;
        }

        assetFlowType = assetFlowTypeMapper.selectAssetFlowTypeById(id);
        if(assetFlowType != null){
            redisCache.setCacheMapValue(CACHE_MAP, key, assetFlowType);
        }
        return assetFlowType;
    }

    /**
     * 查询工单流程列表
     * 
     * @param assetFlowType 工单流程
     * @return 工单流程
     */
    @Override
    public List<AssetFlowType> selectAssetFlowTypeList(AssetFlowType assetFlowType)
    {
        return assetFlowTypeMapper.selectAssetFlowTypeList(assetFlowType);
    }

    /**
     * 新增工单流程
     * 
     * @param assetFlowType 工单流程
     * @return 结果
     */
    @Override
    public int insertAssetFlowType(AssetFlowType assetFlowType)
    {
        return assetFlowTypeMapper.insertAssetFlowType(assetFlowType);
    }

    /**
     * 修改工单流程
     * 
     * @param assetFlowType 工单流程
     * @return 结果
     */
    @Override
    public int updateAssetFlowType(AssetFlowType assetFlowType)
    {
        return assetFlowTypeMapper.updateAssetFlowType(assetFlowType) +  reCache();
    }

    /**
     * 批量删除工单流程
     * 
     * @param ids 需要删除的工单流程主键
     * @return 结果
     */
    @Override
    public int deleteAssetFlowTypeByIds(Long[] ids)
    {
        return assetFlowTypeMapper.deleteAssetFlowTypeByIds(ids)+  reCache();
    }

    /**
     * 删除工单流程信息
     * 
     * @param id 工单流程主键
     * @return 结果
     */
    @Override
    public int deleteAssetFlowTypeById(Long id)
    {
        return assetFlowTypeMapper.deleteAssetFlowTypeById(id)+  reCache();
    }
}
